import axios from "axios";

const service = axios.create({
    baseURL: '/front',
    //baseURL: 'http://localhost:8888',
    timeout: 5000
})

service.interceptors.response.use(
    (response) => {

        if (Array.isArray(response.data.data)) {
            // 如果 response.data.data 是数组
            response.data.data.forEach((item) => {
                if (typeof item === "object") {

                    for (let key in item) {

                        if (typeof item[key] === "string" && item[key] === 'null') {
                            // 如果属性值是字符串并且为 'null'，则替换为空字符串
                            item[key] = '';
                        }
                    }

                }
            });
        } else {
            const data = response.data.data
            for (let key in data) {
                if (typeof data[key] === 'string' && data[key] === 'null') {
                    data[key] = '';
                }
            }
        }

        return response;
    },
    (error) => {
        return Promise.reject(error);
    }
);



export default service
